package com.fdc_project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fdc_project.entity.Doingproject;
import com.fdc_project.entity.Historyproject;
import com.fdc_project.mapper.HistoryprojectMapper;
import com.fdc_project.service.IHistoryprojectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fdc_project.vo.ErrorCode;
import com.fdc_project.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Sk
 * @since 2021-11-29
 */
@Service
public class HistoryprojectServiceImpl extends ServiceImpl<HistoryprojectMapper, Historyproject> implements IHistoryprojectService {

    @Autowired
    HistoryprojectMapper historyprojectMapper;


    @Override
    public void autoAddHistory(Doingproject doingproject) {
        Historyproject historyproject = new Historyproject();
        historyproject.setStaffId(doingproject.getStaffId());
        historyproject.setProId(doingproject.getProId());
        historyproject.setProName(doingproject.getProName());
        doingproject.getCountDown();doingproject.getAllocateTime();
        historyprojectMapper.insert(historyproject);
    }

    @Override
    public Result staffHistory(Integer staff_id){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("staff_id",staff_id);
        List list = historyprojectMapper.selectList(queryWrapper);
        if(list.isEmpty()){
            return Result.fail(ErrorCode.PARAMS_ERROR.getCode(),"该职员未含有任何历史项目！");
        }
        return Result.success(list);
    }


}
